var _xvr;

/**********************************************************************
 * 	Loading all the needed script files
 **********************************************************************/
(function(){
	var parent = getScriptTag().parentNode;
	loadXVRConstantsJS(parent);
}());


function loadXVRConstantsJS(parent){
	var location = _fxb_domain + 'xvr/xvr_const.js'; 
	parent.appendChild(newScriptElement(location, true, function(){
		loadXVRJS(parent);
	}));
}

function loadXVRJS(parent){
	var location = _fxb_domain + 'xvr/xvr.js'; 
	parent.appendChild(newScriptElement(location, true, function(){
		_xvr = new XVR();
		_xvr.addListener(xvr_events.onError, function(){
			alert(_xvr.getFormattedErrorMessage());
		});
		//_xvr.init();
		
		if(window.on_xvr_load_completed != undef && typeof(window.on_xvr_load_completed) == 'function')
			window.on_xvr_load_completed();
	}));
}


function newScriptElement(src_loc, async, onComplete) {
	var script = document.createElement('script');
	script.src = src_loc;
	if(async != null)
		script.async = async;
	script.setAttribute("type", "text/javascript");

	if(onComplete){		
		script.onload = onComplete; //for gecko browser
		script.onreadystatechange = function(){ //for IE
			if (this.readyState == 'complete'){
				onComplete();
			}
		}
	}
	return script;
}

